package com.broadsoft.platform.wfengine.runtime.nodehandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.broadsoft.platform.wfengine.NodeType;
import com.broadsoft.platform.wfengine.parser.ParsedWorkflowDefinition;
import com.broadsoft.platform.wfengine.runtime.WfContext;
import com.broadsoft.platform.wfengine.runtime.impl.NodeExecutionServiceImpl;

public class GeneralNodeExecutionHandler implements INodeExecutionHandler {

    private final static Logger logger = LoggerFactory.getLogger(NodeExecutionServiceImpl.class);
    public GeneralNodeExecutionHandler(ParsedWorkflowDefinition parsedWorkflowInfo){
        this.parsedWorkflowInfo=parsedWorkflowInfo; 
        
    }
    @Override
    public NodeType executeNode(NodeType currentNode, WfContext flowContext) {
        if (logger.isTraceEnabled()) {
            logger.trace("The method[executeGeneralNode] begin");
        }
        flowContext.setPreviousNode(currentNode);
        NodeType nextNode = parsedWorkflowInfo.getNodeTypeByName(flowContext.getWorkflowType().getName(), currentNode
                .getDestNode().get(0));
        if (logger.isTraceEnabled()) {
            logger.trace("The local variable [nextNode] is {}.", nextNode.getName());
            logger.trace("The method[executeGeneralNode] end");
        }
        return nextNode;
    }

    private ParsedWorkflowDefinition parsedWorkflowInfo;

    public ParsedWorkflowDefinition getParsedWorkflowInfo() {
        return parsedWorkflowInfo;
    }

    public void setParsedWorkflowInfo(ParsedWorkflowDefinition parsedWorkflowInfo) {
        this.parsedWorkflowInfo = parsedWorkflowInfo;
    }
}
